<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('仓库信息列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label for="wareName">仓库名称：</label>
                            <input type="text" name="wareName" id="wareName"/>
                        </li>
                        <li>
                            <label for="mkOrderIndent" >订单编号：</label>
                            <input type="text" name="mkOrderIndent" id="mkOrderIndent"/>
                        </li>
                        <li>
                            <label for="status" >状态：</label>
                            <select name="status" id="status" >
                                <option value="" selected>--请选择--</option>
                                <option value="1">--未发货--</option>
                                <option value="2">--已发货--</option>
                                <option value="3">--已回款--</option>
                                <option value="4">--取消订单--</option>
                                <option value="5">--已退货--</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="storage:ck:add">
                <i class="fa fa-plus"></i> 添加
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('storage:ck:edit')}]];
    var removeFlag = [[${@permission.hasPermi('storage:ck:remove')}]];
    var detailFlag = [[${@permission.hasPermi('storage:ck:detail')}]];
    var prefix = ctx + "storage/ck";

    function numFormat(num) {
        var c = (num.toString().indexOf ('.') !== -1) ? num.toLocaleString() : num.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
        return c;
    }

    function editStatus(status,id){
        $.ajax({
            type : "get",
            url : ctx + "storage/ck/edit",
            data: {
                "status" : status,
                "ckId" : id
            },
            dataType : "json",//预期服务器返回的数据类型
            success : function () {
                // $.modal.alertSuccess("更改成功");
                $.modal.msgSuccess("更改成功");
                $.table.refresh();
            },
            error : function (){
                $.modal.msgWarning("更改有误！");
            }

        });
        $.table.refresh();
    }

    $(function() {

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{status}/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail/{id}",
            modalName: "出库信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'ckId',
                    title: '编号',
                    visible: false
                },
                {
                    title: "序号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'mkOrderIndent',
                    title: '订单编号'
                },
                {
                    field: 'total',
                    title: '金额',
                    formatter: function(value) {
                        var qianzhui ='￥';
                        if (value != null){
                            return qianzhui + numFormat(value);
                        }
                    }
                },
                {
                    field: 'wareName',
                    title: '仓库名称'
                },
                {
                    field: 'ckTime',
                    title: '出库时间'
                },
                {
                    field: 'ckUserName',
                    title: '出库人名'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value) {
                        switch (value){
                            case '1': return "未发货";
                            case '2': return "已发货";
                            case '3': return "已回款";
                            case '4': return "取消订单";
                            case '5': return "已退货";
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.wareId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.wareId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-warning btn-xs '+detailFlag+' " href="javascript:void(0)" onclick="$.operate.detail(\'' + row.ckId + '\')"><i class="fa fa-search"></i>详细</a>');
                        if (row.status == '1') {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" onclick="editStatus(2,' + row.ckId + ')"></i>发货</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" onclick="editStatus(4,' + row.ckId + ')"></i>取消订单</a> ');
                        }
                        if (row.status == '2') {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" onclick="editStatus(3,' + row.ckId + ')"></i>确认回款</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" onclick="editStatus(4,' + row.ckId + ')"></i>取消订单</a> ');
                        }
                        if (row.status == '3') {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" onclick="editStatus(4,' + row.ckId + ')"></i>取消订单</a> ');
                        }
                        if (row.status == '4') {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" onclick="editStatus(5,' + row.ckId + ')"></i>确认已退货</a> ');
                        }


                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);


    });
</script>
</body>
</html>